<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
     编写一个方法 queryUrlParmeter,实现把一个URL地址问号传参部分的信息获取到,并且解析为对象键值对的方式,例如：
    URL地址：
      'https://www.baidu.com/s?wd=javascript&rsv_spt=1'
    解析结果为:
      {wd:'javascript',rsv_spt:1}
   -->
</head>

<body>
    <script>
        let url = 'https://www.baidu.com/s?wd=javascript&rsv_spt=1';

        // function queryUrlParmeter() {
        //     let obj = {};
        //     let reg = /([^?=&]+)=([^?=&]+)/g;
        //     url.replace(reg, function() {
        //         // console.log(arguments);
        //         obj[arguments[1]] = arguments[2];
        //     });
        //     return obj
        // }
        // let result = queryUrlParmeter(url);
        // console.log(result);
        String.prototype.myQueryUrlParmeter = function() {
            let reg = /([^&=?]+)=([^?=&]+)/g;
            let obj = {};
            this.replace(reg, function() {
                obj[arguments[1]] = arguments[2];
            });
            return obj;
        }
        let res = url.myQueryUrlParmeter();
        console.log(res);
        // let url = 'https://www.baidu.com/s?wd=javascript&rsv_spt=1';
        // String.prototype.getUrl1 = function() {
        //     let obj = {};
        //     let reg = /([^&?=]+)=([^&?=]+)/g;
        //     this.replace(reg, (...arg) => {
        //         obj[arg[1]] = arg[2];
        //         console.log(arg)
        //     });
        //     return obj;
        // }
        // let res1 = url.getUrl1();
        // console.log(res1);
        // res1 = null;
    </script>
</body>

</html>